#include <Wire.h>
#include "lcd_i2c.h"

void(* resetFunc)(void) = 0;

LcdI2c* lcd = 0;

void setup() {
    Serial.begin(9600);
    while (!Serial) {
    }

    Serial.println();
    Serial.println("I2C scanner. Scanning ...");
    byte count = 0;
    Wire.begin();
    for (byte i = 1; i < 127; i++) {
        Wire.beginTransmission(i);
        if (Wire.endTransmission() == 0) {
            Serial.print("Found address: ");
            Serial.print(i, DEC);
            Serial.print(" (0x");
            Serial.print(i, HEX);
            Serial.println(")");
            if (lcd == 0) {
                lcd = new LcdI2c(i, 16, 2);
            }
            count++;
            delay(1);
        }
    }
    Serial.print("Found ");
    Serial.print(count, DEC);
    Serial.println(" device(s).");

    if (lcd != 0) {
        lcd->init();
        lcd->backlight();
        //lcd->noBacklight();

        lcd->clear();
        lcd->write('1');
    } else {
        resetFunc();
    }
}

/*
void loop() {
    // when characters arrive over the serial port...
    if (Serial.available()) {
        // wait a bit for the entire message to arrive
        delay(100);
        // clear the screen
        lcd->clear();
        // read all the available characters
        while (Serial.available() > 0) {
            // display each character to the LCD
            lcd->write(Serial.read());
        }
    }
}
*/

void loop() {
}
